extends Control

@onready var life_label: Label = $MarginContainer/Control/Parent/Life/Label
@onready var attack_label: Label = $MarginContainer/Control/Parent/Attack/Label
@onready var defense_label: Label = $MarginContainer/Control/Parent/Defense/Label
@onready var exp_label: Label = $MarginContainer/Control/Parent/Exp/Label
@onready var gold_label: Label = $MarginContainer/Control/Parent/Gold/Label
@onready var key_count_label: Label = $MarginContainer/Control/KeyInfo/Label
@onready var big_key_count_label: Label = $MarginContainer/Control/BigKeyInfo/Label


func _ready() -> void:
	GlobalSignals.player_info_changed.connect(handler_player_info_changed)


func handler_player_info_changed():
	life_label.text = str(GlobalData.player_data.hp) + " / " + str(GlobalData.player_data.max_hp)
	
	var total_attack = GlobalData.player_data.get_attack() + GlobalData.player_data.get_hold_item_attack()
	attack_label.text = "%s ( %s + %s | %%%s %%%s )" % \
	[str(total_attack), str(GlobalData.player_data.get_attack()), str(GlobalData.player_data.get_hold_item_attack()), str(int(GlobalData.player_data.get_hold_item_critical_rate() * 100)), str(int(GlobalData.player_data.get_hold_item_critical_bonus() * 100))] 
	
	defense_label.text ="%s ( %s + %s )" % \
	[str(GlobalData.player_data.get_defense_with_equip()), \
	str(GlobalData.player_data.get_defense()),
	str(GlobalData.player_data.get_equip_defense())]
	
	exp_label.text = str(GlobalData.player_data.exp) + " / " + str(GlobalData.player_data.get_next_level_need_exp()) + " / lvl" + str(GlobalData.player_data.level) 
	
	gold_label.text = str(GlobalData.player_data.gold)
	
	key_count_label.text = str(GlobalData.player_data.little_key_num) 
	big_key_count_label.text = str(GlobalData.player_data.big_key_num)
